package com.wondertek.web.controller.business;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wondertek.common.base.Result;
import com.wondertek.common.util.security.PreAuthorize;
import com.wondertek.service.dto.business.req.SiteAddReq;
import com.wondertek.service.dto.business.req.SitePageReq;
import com.wondertek.service.dto.business.req.SiteUpdateReq;
import com.wondertek.service.dto.business.res.SiteDetailRes;
import com.wondertek.service.dto.sys.req.BaseUpdateReq;
import com.wondertek.service.entity.business.SitePo;
import com.wondertek.service.service.business.SiteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @description: 站点管理
 * @author: qinjianhui
 * @create: 2024-07-16 14:01
 **/
@RestController
@RequestMapping("/backend/business/site/")
@Tag(name = "站点管理")
public class SiteController {

    @Resource
    private SiteService siteService;

    @PostMapping("/add")
    @Operation(summary = "新增站点")
    @PreAuthorize("@el.check('backend:business:site:add')")
    public Result<?> addSite(@RequestBody @Validated SiteAddReq siteAddReq){
        siteService.addSite(siteAddReq);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除站点")
    @PreAuthorize("@el.check('backend:business:site:delete')")
    public Result<?> deleteSite(@RequestBody @Validated BaseUpdateReq baseUpdateReq){
        siteService.deleteSite(baseUpdateReq.getId());
        return Result.success();
    }

    @PostMapping("/page")
    @Operation(summary = "查询站点")
    @PreAuthorize("@el.check('backend:business:site:page','backend:sys:user:page','backend:sys:log:page')")
    public Result<Page<SitePo>> page(@RequestBody SitePageReq sitePageReq){
        Page<SitePo> page = siteService.page(sitePageReq);
        return Result.success(page);
    }

    @PostMapping("/detail")
    @Operation(summary = "查询详情")
    @PreAuthorize("@el.check('backend:business:site:detail')")
    public Result<SiteDetailRes> page(@RequestBody BaseUpdateReq req){
        return Result.success(siteService.detail(req.getId()));
    }

    @PostMapping("/update")
    @Operation(summary = "修改站点")
    @PreAuthorize("@el.check('backend:business:site:update')")
    public Result<?> updateSite(@RequestBody @Validated SiteUpdateReq siteUpdateReq){
        siteService.updateSite(siteUpdateReq);
        return Result.success();
    }

    @PostMapping("/list")
    @Operation(summary = "查询站点列表")
    public Result<List<SitePo>> list(){
        List<SitePo> list = siteService.list();
        return Result.success(list);
    }
}

